package com.bootx.entity;

import com.bootx.common.BaseAttributeConverter;
import com.bootx.pojo.PredictInfo;
import com.fasterxml.jackson.annotation.JsonView;
import jakarta.persistence.*;
import org.apache.commons.lang3.StringUtils;
import org.hibernate.annotations.Comment;

import java.util.*;

/**
 * @author black
 */
@Entity
@Table(
        indexes = {
                @Index(name = "lotteryCode_sn_index",columnList = "lotteryCode,sn",unique = true),
                @Index(name = "lotteryCode_index",columnList = "lotteryCode"),
                @Index(name = "sn_index",columnList = "sn"),
                @Index(name = "date_index",columnList = "date")
        }
)
public class LotteryRecord extends OrderedEntity<Long>{

    private Long lotteryCode;

    @JsonView({IdView.class})
    private Date drawTime;

    @Comment("开奖号码")
    @JsonView({IdView.class})
    private String drawCode;

    @JsonView({IdView.class})
    private Long sn;

    @Column(length = 4000)
    private String openInfo;

    @Convert(converter = PredictInfoConverter.class)
    @Column(length = 1000)
    @JsonView({IdView.class})
    private List<PredictInfo> predictInfo = new ArrayList<>();

    @JsonView({IdView.class})
    private Double betMoney;

    @JsonView({IdView.class})
    private Double winMoney;

    private String date;

    /**
     * 0：未预测
     * 1：已预测
     */
    private Integer predictResult;

    @JsonView({IdView.class})
    private Integer predictNumIndex;

    @JsonView({IdView.class})
    private String predictType;

    public Long getLotteryCode() {
        return lotteryCode;
    }

    public void setLotteryCode(Long lotteryCode) {
        this.lotteryCode = lotteryCode;
    }

    public Date getDrawTime() {
        return drawTime;
    }

    public void setDrawTime(Date drawTime) {
        this.drawTime = drawTime;
    }

    public String getDrawCode() {
        return drawCode;
    }

    public void setDrawCode(String drawCode) {
        this.drawCode = drawCode;
    }

    public Long getSn() {
        return sn;
    }

    public void setSn(Long sn) {
        this.sn = sn;
    }

    public String getOpenInfo() {
        return openInfo;
    }

    public void setOpenInfo(String openInfo) {
        this.openInfo = openInfo;
    }

    public Double getBetMoney() {
        return betMoney;
    }

    public void setBetMoney(Double betMoney) {
        this.betMoney = betMoney;
    }

    public String getDate() {
        return date;
    }

    public void setDate(String date) {
        this.date = date;
    }

    public Double getWinMoney() {
        return winMoney;
    }

    public void setWinMoney(Double winMoney) {
        this.winMoney = winMoney;
    }

    public List<PredictInfo> getPredictInfo() {
        return predictInfo;
    }

    public void setPredictInfo(List<PredictInfo> predictInfo) {
        this.predictInfo = predictInfo;
    }

    public Integer getPredictResult() {
        return predictResult;
    }

    public void setPredictResult(Integer predictResult) {
        this.predictResult = predictResult;
    }

    public Integer getPredictNumIndex() {
        return predictNumIndex;
    }

    public void setPredictNumIndex(Integer predictNumIndex) {
        this.predictNumIndex = predictNumIndex;
    }

    public String getPredictType() {
        return predictType;
    }

    public void setPredictType(String predictType) {
        this.predictType = predictType;
    }

    @Convert
    public static class PredictInfoConverter extends BaseAttributeConverter<List<PredictInfo>>{

    }

    public List<Integer> getDrawNums(){
        List<Integer> drawNums = new ArrayList<>();
        if(StringUtils.isNotEmpty(drawCode)){
            for(String num:drawCode.split(",")){
                drawNums.add(Integer.valueOf(num));
            }
        }
        return drawNums;
    }
}

